﻿namespace Algo.Sort
{
    using System;
    using System.Collections.Generic;

    using JetBrains.Annotations;

    internal static class SortUtilities
    {
        public static void Swap<T>([NotNull] IList<T> list, int position1, int position2)
        {
            var tempItem = list[position1];
            list[position1] = list[position2];
            list[position2] = tempItem;
        }

        public static bool IsGreaterThen<T>([NotNull] IComparer<T> comparer, T item1, T item2)
        {
            return comparer.Compare(item1, item2) > 0;
        }

        public static IList<T> CopyToList<T>(IEnumerable<T> enumerable)
        {
            var array = enumerable as T[];
            if (array != null)
            {
                var newArray = new T[array.Length];
                Array.Copy(array, newArray, array.Length);
                return newArray;
            }

            return new List<T>(enumerable);
        }
    }
}